﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace CPPEI.Coolzon.UI
{
    public delegate void ViewCloseEventHandle(View view, bool isCancel);

    public class View : UserControl
    {
        public event ViewCloseEventHandle Close;

        /// <summary>
        /// 视图第一次被激活
        /// </summary>
        public bool IsFirstActive { get; private set; }

        /// <summary>
        /// 视图是否处于活动状态
        /// </summary>
        public bool IsActived { get; private set; }

        public View()
        {
            IsFirstActive = true;
        }

        public void Submit()
        {
            OnClose();
            if (Close != null)
            {
                Close(this, false);
            }
        }

        public void Cancel()
        {
            OnClose();
            if (Close != null)
            {
                Close(this, true);
            }
        }

        public void Active()
        {
            if (!IsActived)
            {
                OnActive();
                IsFirstActive = false;
                IsActived = true;
            }
        }

        protected virtual void OnActive()
        {
        }

        public void Deactive()
        {
            if (IsActived)
            {
                OnDeactive();
                IsActived = false;
            }
        }

        /// <summary>
        /// 销毁视图
        /// </summary>
        public void Destory()
        {
            OnDestory();
        }

        protected virtual void OnDestory()
        {
        }

        protected virtual void OnDeactive()
        {
        }

        protected virtual void OnClose()
        {
        }

        public void ShowMessage(MessageType messageType, string message)
        {
            System.Windows.MessageBox.Show(message);
        }
    }

    public enum MessageType
    {
        Info,
        Error,
        Warning,
    }
}
